home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /** header ******************************************************************/
-
- /*
- * $Source$
- * $Revision$
- * $Date$
- * $Author$
- *
- * creator: Brett Bainter
- *
- * purpose:
- * mixed model program demonstrating
- * ...multiple server connections
- * ...placing apps in non-default visuals
- * ...workprocs
- * ...working with XImages
- *
- * compiling:
- * cc -float -prototypes -O macx.c -o macx \
- * -s -lXirisw -lXm_s -lXt_s -lgl_s -lX11_s -lm -lc_s -lPW
- *
- * operating:
- * usage: macx [remote-display-spec]
- *
- * description:
- *
- * For this program the term "mac" represents a hypothetical x server running
- * on a mac which happens to support a 24 bit TrueColor visual.
- */
-
- /** notes *******************************************************************/
-
- /*
- * - this seems to have a slight bug, but i haven't been able to locate it.
- * sometimes when it is started it hangs after opening up just the sgi
- * side of things. it's hard to reproduce but does happen occasionally.
- */
-
- /** includes ****************************************************************/
-
- #include <stdio.h> /* standard */
- #include <Xm/Xm.h> /* for motif */
- #include <Xm/DrawingA.h> /* motif widget */
- #include <Xm/Form.h> /* motif widget */
- #include <Xm/Frame.h> /* motif widget */
- #include <Xm/PushB.h> /* motif widget */
- #include <Xm/RowColumn.h> /* motif widget */
- #include <Xm/Separator.h> /* motif widget */
- #include <X11/Xirisw/GlxMDraw.h> /* gl widget */
-
- /** defines *****************************************************************/
-
- /* c environment */
- #define global
-
- /* colors */
- #define RGB_BACKGROUND 0x00555555
-
- /** typedefs ****************************************************************/
- /** prototypes **************************************************************/
-
- extern void main(int argc, char *argv[], char *envp[]);
-
- /* setup */
- static void create_sgi_app(int *argc, char *argv[]);
- static void create_mac_app(int *argc, char *argv[]);
- static void install_colormaps(Widget top_level, Widget glw);
-
- /* callbacks (gl widget) */
- static void cb_gl_expose(Widget w, XtPointer client_data, XtPointer call_data);
- static void cb_gl_resize(Widget w, XtPointer client_data, XtPointer call_data);
- static void cb_gl_ginit(Widget w, XtPointer client_data, XtPointer call_data);
- static void cb_gl_input(Widget w, XtPointer client_data, XtPointer call_data);
-
- /* callbacks (canvas) */
- static void cb_can_expose(Widget w, XtPointer client_data, XtPointer call_data);
- static void cb_can_resize(Widget w, XtPointer client_data, XtPointer call_data);
-
- /* callbacks (misc) */
- static void cb_quit(Widget w, XtPointer client_data, XtPointer call_data);
- static void cb_xfer(Widget w, XtPointer client_data, XtPointer call_data);
-
- /* work procedures */
- static Boolean wp_anim(XtPointer client_data);
-
- /* etc */
- static void glw_resize(void);
- static void glw_save(void);
- static void glw_transfer(void);
- static void canvas_load(void);
-
- /* drawing */
- static void draw_frame(char *ops);
- static void model_cube_shaded(void);
-
- /** variables ***************************************************************/
-
- /* mixed-model configuration */
- static GLXconfig glx_config[] = {
- {GLX_NORMAL, GLX_RGB, TRUE},
- {GLX_NORMAL, GLX_DOUBLE, TRUE},
- {GLX_NORMAL, GLX_ZSIZE, GLX_NOCONFIG},
- {0, 0, 0},
- };
-
- /* application context for all display connections */
- static XtAppContext app_context;
-
- static struct { /* SGI CONNECTION */
- Display *dsp; /* display ref */
- int screen; /* the default one */
- Widget app_shell; /* first widget */
- GC gc; /* graphics context */
- /**/
- Widget glw; /* can do gl rendering in this guy */
- int im_width, im_height; /* image size */
- float im_aspect; /* image width to height */
- unsigned long *im_data; /* malloc'ed array for image data */
- } sgi1;
-
- static struct { /* MAC CONNECTION */
- Display *dsp; /* display ref */
- int screen; /* the default one */
- Widget app_shell; /* first widget */
- GC gc; /* graphics context */
- /**/
- XVisualInfo vinfo; /* for finding desired visual */
- Visual *visual; /* hopefully we get one we want */
- Colormap cmap; /* colormap which jives with visual */
- Widget canvas; /* for holding image */
- XImage *x_image; /* handle to the image we use for transfer */
- int im_width, im_height; /* image size */
- float im_aspect; /* image width to height */
- unsigned long *im_data; /* malloc'ed array for image data */
- } mac1;
-
- /** functions ***************************************************************/
-
- /*
- * main - program entry point.
- */
- global void main(
- int argc, /* argument count */
- char *argv[], /* argument vector */
- char *envp[] /* environment pointer */
- )
- {
- /* setup the intrinsics */
- XtToolkitInitialize();
-
- /* create our single application context */
- app_context = XtCreateApplicationContext();
-
- /* setup each app */
- create_sgi_app(&argc, argv);
- create_mac_app(&argc, argv);
-
- /* realize the apps, creating the actual x windows */
- XtRealizeWidget(sgi1.app_shell);
- install_colormaps(sgi1.app_shell, sgi1.glw);
- XtRealizeWidget(mac1.app_shell);
-
- /* create graphics context now that windows are available */
- mac1.gc = XCreateGC(mac1.dsp, XtWindow(mac1.canvas), 0L, NULL);
-
- /* setup initial gl image area now that sizes are known */
- glw_resize();
-
- /* enter the event loop */
- XtAppMainLoop(app_context);
- }
-
-
- /*- support: setup ---------------------------------------------------------*/
- /*
- * create_sgi_app -
- */
- static void create_sgi_app(int *argc, char *argv[])
- {
- XtWorkProcId wpid_anim; /* animation work proc */
- Widget form; /* surrounds app */
- Widget rowcol; /* manages input buttons */
- Widget button[2]; /* buttons */
- Widget separator; /* between input and output */
- Widget frame; /* to surround gl widget */
- Arg args[15]; /* for name/value pairs */
- int n; /* reusable indices */
-
- /* connect to display */
- n = 0;
- sgi1.dsp = XtOpenDisplay(app_context, "", argv[0], "Sgi", args, n,
- argc, argv
- );
- sgi1.screen = DefaultScreen(sgi1.dsp);
-
- /* create application shell */
- n = 0;
- XtSetArg(args[n], XmNgeometry, "400x300+100+350"); n++;
- XtSetArg(args[n], XmNtitle, "SGI Display"); n++;
- sgi1.app_shell = XtAppCreateShell("sgi", "Sgi",
- applicationShellWidgetClass, sgi1.dsp, args, n
- );
-
- /* create container for app */
- n = 0;
- form = XmCreateForm(sgi1.app_shell, "form", args, n);
- XtManageChild(form);
-
- /* create the command area */
- n = 0;
- XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
- rowcol = XmCreateRowColumn(form, "rowcol", args, n);
- XtManageChild(rowcol);
-
- /* create the command area buttons */
- n = 0;
- button[0] = XmCreatePushButton(rowcol, "Quit", args, n);
- XtAddCallback(button[0], XmNactivateCallback, cb_quit, NULL);
- button[1] = XmCreatePushButton(rowcol, "Send", args, n);
- XtAddCallback(button[1], XmNactivateCallback, cb_xfer, "sgi-put");
- XtManageChildren(button, XtNumber(button));
-
- /* create separator between command area and output area */
- n = 0;
- XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
- XtSetArg(args[n], XmNleftWidget, rowcol); n++;
- XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
- separator = XmCreateSeparator(form, "separator", args, n);
- XtManageChild(separator);
-
- /* create the output area */
- /* create the frame */
- n = 0;
- XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
- XtSetArg(args[n], XmNleftWidget, separator); n++;
- XtSetArg(args[n], XmNleftOffset, 5); n++;
- XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNrightOffset, 5); n++;
- XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNbottomOffset, 5); n++;
- XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNtopOffset, 5); n++;
- XtSetArg(args[n], XmNshadowThickness, 6); n++;
- frame = XmCreateFrame(form, "frame", args, n);
- XtManageChild(frame);
-
- /* create the gl widget */
- n = 0;
- XtSetArg(args[n], GlxNglxConfig, glx_config); n++;
- XtSetArg(args[n], XmNborderWidth, 0); n++;
- sgi1.glw = GlxCreateMDraw(frame, "glw", args, n);
- XtManageChild(sgi1.glw);
- XtAddCallback(sgi1.glw, GlxNexposeCallback, cb_gl_expose, 0);
- XtAddCallback(sgi1.glw, GlxNresizeCallback, cb_gl_resize, 0);
- XtAddCallback(sgi1.glw, GlxNginitCallback, cb_gl_ginit, 0);
- XtAddCallback(sgi1.glw, GlxNinputCallback, cb_gl_input, 0);
-
- /* setup work procedure */
- wpid_anim = XtAppAddWorkProc(app_context, wp_anim, sgi1.glw);
- }
-
-
- /*
- * create_mac_app -
- *
- * This app does not use the gl widget. It is expected to run on a vanilla
- * X/Motif system. We attempt to place this application in a 24 bit TrueColor
- * visual.
- */
- static void create_mac_app(int *argc, char *argv[])
- {
- #define VISDEPTH 24
- #define VISCLASS TrueColor
- #define LOCDISP ""
- #define MACDISP "einstein:0.0"
- /**/
- Widget form; /* surrounds app */
- Widget rowcol; /* manages input buttons */
- Widget button[2]; /* buttons */
- Widget separator; /* between input and output */
- Widget frame; /* to surround the canvas */
- Arg args[15]; /* for name/value pairs */
- int n; /* reusable indices */
- char *dsp_name; /* could go to remote machine */
-
- /* connect to display */
- dsp_name = *argc<=1? NULL : argv[1];
- n = 0;
- mac1.dsp = XtOpenDisplay(app_context, dsp_name, argv[0], "Mac", args, n,
- argc, argv
- );
- if (mac1.dsp == (Display *) NULL) {
- fprintf(stderr, "ERROR: can't connect to MAC X server %s\n",
- XDisplayName(dsp_name)
- );
- exit(-1);
- }
- mac1.screen = DefaultScreen(mac1.dsp);
-
- /* setup visual ----------------------------------------*/
- if (
- XMatchVisualInfo(mac1.dsp, mac1.screen, VISDEPTH, VISCLASS, &mac1.vinfo)
- == 0
- ) {
- fprintf(stderr, "%s: cannot find needed visual.\n", argv[0]);
- exit(-1);
- }
- mac1.visual = mac1.vinfo.visual;
- /*------------------------------------------------------*/
-
- /* setup colormap --------------------------------------*/
- mac1.cmap = XCreateColormap(mac1.dsp, RootWindow(mac1.dsp, mac1.screen),
- mac1.visual, AllocNone
- );
- /*------------------------------------------------------*/
-
- /* create application shell */
- n = 0;
- XtSetArg(args[n], XmNdepth, VISDEPTH); n++;
- XtSetArg(args[n], XmNcolormap, mac1.cmap); n++;
- XtSetArg(args[n], XmNvisual, mac1.visual); n++;
- XtSetArg(args[n], XmNgeometry, "400x300+550+350"); n++;
- XtSetArg(args[n], XmNtitle, "MAC Display"); n++;
- mac1.app_shell = XtAppCreateShell("mac", "Mac",
- applicationShellWidgetClass, mac1.dsp, args, n
- );
-
- /* create container for app */
- n = 0;
- form = XmCreateForm(mac1.app_shell, "form", args, n);
- XtManageChild(form);
-
- /* create the command area */
- n = 0;
- XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
- rowcol = XmCreateRowColumn(form, "rowcol", args, n);
- XtManageChild(rowcol);
-
- /* create the command area buttons */
- n = 0;
- button[0] = XmCreatePushButton(rowcol, "Quit", args, n);
- XtAddCallback(button[0], XmNactivateCallback, cb_quit, NULL);
- button[1] = XmCreatePushButton(rowcol, "Grab", args, n);
- XtAddCallback(button[1], XmNactivateCallback, cb_xfer, "mac-get");
- XtManageChildren(button, XtNumber(button));
-
- /* create separator between command area and output area */
- n = 0;
- XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
- XtSetArg(args[n], XmNleftWidget, rowcol); n++;
- XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
- separator = XmCreateSeparator(form, "separator", args, n);
- XtManageChild(separator);
-
- /* create the output area */
- /* create the frame */
- n = 0;
- XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
- XtSetArg(args[n], XmNleftWidget, separator); n++;
- XtSetArg(args[n], XmNleftOffset, 5); n++;
- XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNrightOffset, 5); n++;
- XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNbottomOffset, 5); n++;
- XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNtopOffset, 5); n++;
- XtSetArg(args[n], XmNshadowThickness, 6); n++;
- frame = XmCreateFrame(form, "frame", args, n);
- XtManageChild(frame);
-
- /* create the drawing area */
- n = 0;
- XtSetArg(args[n], XmNbackground, RGB_BACKGROUND); n++;
- mac1.canvas = XmCreateDrawingArea(frame, "canvas", args, n);
- XtAddCallback(mac1.canvas, XmNexposeCallback, cb_can_expose, NULL);
- XtAddCallback(mac1.canvas, XmNresizeCallback, cb_can_resize, NULL);
- XtManageChild(mac1.canvas);
-
- /* create image structure which describes are image data */
- /* note: we need this for refreshes of the canvas */
- mac1.x_image = XCreateImage(
- mac1.dsp, mac1.visual, VISDEPTH, ZPixmap, 0,
- NULL, 1, 1, /* dynamic */
- 32, /* 16 works and 8 works too (??) */
- 0 /* dynamic */
- );
- }
-
-
- /*
- * install_colormaps - let the window manager know about our colormaps.
- */
- static void install_colormaps(Widget top_level, Widget glw)
- {
- Window overlay_win, popup_win, underlay_win;
- Window window[5];
- int i;
-
- XtVaGetValues(
- glw,
- GlxNoverlayWindow, &overlay_win,
- GlxNpopupWindow, &popup_win,
- GlxNunderlayWindow, &underlay_win,
- NULL
- );
- i = 0;
- if (overlay_win)
- window[i++] = overlay_win;
- if (popup_win)
- window[i++] = popup_win;
- if (underlay_win)
- window[i++] = underlay_win;
- window[i++] = XtWindow(glw);
- window[i++] = XtWindow(top_level);
- XSetWMColormapWindows(XtDisplay(top_level), XtWindow(top_level), window, i);
- }
-
-
- /*- support: callbacks (gl widget) -----------------------------------------*/
- /*
- * cb_gl_expose - handle expose events for the gl widget.
- */
- static void cb_gl_expose(Widget w, XtPointer client_data, XtPointer call_data)
- {
- GlxDrawCallbackStruct *glx = (GlxDrawCallbackStruct *) call_data;
-
- GLXwinset(XtDisplay(w), XtWindow(w));
- draw_frame("cds");
- }
-
-
- /*
- * cb_gl_resize - handle resize events for the gl widget.
- */
- static void cb_gl_resize(Widget w, XtPointer client_data, XtPointer call_data)
- {
- GlxDrawCallbackStruct *glx = (GlxDrawCallbackStruct *) call_data;
-
- GLXwinset(XtDisplay(w), XtWindow(w));
- glw_resize();
- }
-
-
- /*
- * cb_gl_ginit - perform any necessary graphics initialization.
- */
- static void cb_gl_ginit(Widget w, XtPointer client_data, XtPointer call_data)
- {
- GlxDrawCallbackStruct *glx = (GlxDrawCallbackStruct *) call_data;
-
- GLXwinset(XtDisplay(w), XtWindow(w));
-
- shademodel(GOURAUD);
- zbuffer(TRUE);
- subpixel(TRUE);
- lsetdepth(getgdesc(GD_ZMIN), getgdesc(GD_ZMAX));
- mmode(MVIEWING);
- perspective(300, glx->width/(float)glx->height, 1.0, 50.0);
- polarview(10.0, 0, 0, 0);
- frontbuffer(TRUE);
- cpack(RGB_BACKGROUND);
- clear();
- frontbuffer(FALSE);
- gflush();
- }
-
-
- /*
- * cb_gl_input - handle input from a gl window.
- */
- static void cb_gl_input(Widget w, XtPointer client_data, XtPointer call_data)
- {
- GlxDrawCallbackStruct *glx = (GlxDrawCallbackStruct *) call_data;
-
- GLXwinset(XtDisplay(w), XtWindow(w));
- }
-
-
- /*- support: callbacks (gl widget) -----------------------------------------*/
- /*
- * cb_can_expose -
- */
- static void cb_can_expose(Widget w, XtPointer client_data, XtPointer call_data)
- {
- canvas_load();
- }
-
-
- /*
- * cb_can_resize -
- */
- static void cb_can_resize(Widget w, XtPointer client_data, XtPointer call_data)
- {
- }
-
-
- /*- support: callbacks (misc) ----------------------------------------------*/
- /*
- * cb_quit -
- */
- static void cb_quit(Widget w, XtPointer client_data, XtPointer call_data)
- {
- XDestroyImage(mac1.x_image);
- XFreeGC(mac1.dsp, mac1.gc);
- exit(0);
- }
-
-
- /*
- * cb_xfer -
- */
- static void cb_xfer(Widget w, XtPointer client_data, XtPointer call_data)
- {
- GLXwinset(XtDisplay(sgi1.glw), XtWindow(sgi1.glw));
- glw_save();
- glw_transfer();
- canvas_load();
- }
-
-
- /*- support: work procedures -----------------------------------------------*/
- /*
- * wp_anim - do another frame of animation.
- */
- static Boolean wp_anim(XtPointer client_data)
- {
- Widget glw = (Widget) client_data;
-
- GLXwinset(XtDisplay(glw), XtWindow(glw));
- draw_frame("cdsu");
- return (False);
- }
-
-
- /*- support: etc -----------------------------------------------------------*/
- /*
- * glw_resize - account for changes in the size of the gl widget.
- */
- static void glw_resize(void)
- {
- Arg args[5];
- int n;
- Dimension w, h;
-
- /* obtain gl widget size */
- n = 0;
- XtSetArg(args[n], XmNwidth, &w); n++;
- XtSetArg(args[n], XmNheight, &h); n++;
- XtGetValues(sgi1.glw, args, n);
- sgi1.im_width = w;
- sgi1.im_height = h;
- sgi1.im_aspect = sgi1.im_width / (float) sgi1.im_height;
- #if 0
- printf("glw_resize(%d x %d)\n", sgi1.im_width, sgi1.im_height);
- #endif
-
- /* setup area to save image to */
- if (sgi1.im_data != (unsigned long *) NULL) {
- free((void *) sgi1.im_data);
- }
- sgi1.im_data = (unsigned long *) malloc(w*h*sizeof(sgi1.im_data[0]));
- if ((char *)sgi1.im_data == NULL) {
- fprintf(stderr, "ERROR: malloc failed for gl widget image array.\n");
- exit(-1);
- }
-
- /* setup gl for new size */
- viewport(0, sgi1.im_width-1, 0, sgi1.im_height-1);
- perspective(300, sgi1.im_aspect, 1.0, 50.0);
- }
-
-
- /*
- * glw_save - copy the gl widget image to the image data array.
- */
- static void glw_save(void)
- {
- lrectread(0, 0, sgi1.im_width-1, sgi1.im_height-1, sgi1.im_data);
- gflush();
- }
-
-
- /*
- * glw_transfer - convert sgi image data to an X format.
- *
- * Our job for a 24 bit visual is simple: we just flip the image to account
- * for the difference in the X and GL y axes. Because of the simplicity of
- * this we can convert the image in place without the need to allocate a
- * destination image. No big whoop.
- *
- * If the vanilla visual is 8 bit PseudoColor then big whoop.
- */
- static void glw_transfer(void)
- {
- register int i, j;
- register int lo_row, hi_row;
- register unsigned long temp;
- int midpoint = sgi1.im_height/2;
-
- /* flip image in place */
- for (i=0; i<midpoint; i++) {
- hi_row = i*sgi1.im_width;
- lo_row = ((sgi1.im_height-1)-i)*sgi1.im_width;
- for (j=0; j<sgi1.im_width; j++) {
- /* swap pixel from lo to hi rows */
- temp = sgi1.im_data[lo_row+j];
- sgi1.im_data[lo_row+j] = sgi1.im_data[hi_row+j];
- sgi1.im_data[hi_row+j] = temp;
- }
- }
-
- /* the mac image is really our image area */
- mac1.im_width = sgi1.im_width;
- mac1.im_height = sgi1.im_height;
- mac1.im_aspect = sgi1.im_aspect;
- mac1.im_data = sgi1.im_data;
- mac1.x_image->width = mac1.im_width;
- mac1.x_image->height = mac1.im_height;
- mac1.x_image->bytes_per_line = mac1.im_width*sizeof(mac1.im_data[0]);
- mac1.x_image->data = (char *) mac1.im_data;
- }
-
-
- /*
- * canvas_load - load the mac image into the canvas.
- */
- static void canvas_load(void)
- {
- XClearWindow(mac1.dsp, XtWindow(mac1.canvas));
- if (mac1.x_image->data != NULL) {
- XPutImage(
- mac1.dsp, XtWindow(mac1.canvas), mac1.gc, mac1.x_image,
- 0, 0, 0, 0, mac1.im_width, mac1.im_height
- );
- }
- XFlush(mac1.dsp);
- }
-
-
- /*- support: drawing -------------------------------------------------------*/
- /*
- * draw_frame -
- */
- static void draw_frame(char *ops)
- {
- static Angle rx = 0;
- static Angle ry = 0;
- static Angle rz = 0;
-
- for (; *ops != '\0'; ops++) {
- switch (ops[0]) {
- case 'c': /* clear */
- czclear(RGB_BACKGROUND, getgdesc(GD_ZMAX));
- break;
- case 'd': /* draw */
- pushmatrix();
- rotate(rz, 'z');
- rotate(ry, 'y');
- rotate(rx, 'x');
- model_cube_shaded();
- popmatrix();
- break;
- case 's': /* swap */
- swapbuffers();
- gflush();
- break;
- case 'u': /* update */
- /* next angle */
- rx = (rx + 10) % 3600;
- ry = (ry + 10) % 3600;
- rz = (rz + 10) % 3600;
- break;
- default:
- break;
- }
- }
- }
-
-
- /*
- * model_cube_shaded - draw a smooth shaded cube.
- *
- * - borrowed from ivan.
- */
- static void model_cube_shaded(void)
- {
- static long v1[4][3] = {
- {-1, -1, 1},
- { 1, -1, 1},
- { 1, 1, 1},
- {-1, 1, 1},
- };
- static long v2[4][3] = {
- {-1, -1, -1},
- {-1, 1, -1},
- { 1, 1, -1},
- { 1, -1, -1},
- };
- static long colors1[] = {
- 0x000000FF,
- 0x00FF0000,
- 0x0000FF00,
- 0x00FFFF00,
- };
- static long colors2[] = {
- 0x0000FFFF,
- 0x00FF00FF,
- 0x00FFFFFF,
- 0x0FF00000,
- };
- /**/
- register int i;
-
- bgnpolygon();
- for(i=0; i<4; i++) {
- cpack(colors1[i]);
- v3i(v1[i]);
- }
- endpolygon();
- bgnpolygon();
- for(i=0; i<4; i++) {
- cpack(colors2[i]);
- v3i(v2[i]);
- }
- endpolygon();
-
- bgnpolygon();
- cpack(colors1[1]);
- v3i(v1[1]);
- cpack(colors1[2]);
- v3i(v1[2]);
- cpack(colors2[2]);
- v3i(v2[2]);
- cpack(colors2[3]);
- v3i(v2[3]);
- endpolygon();
- bgnpolygon();
- cpack(colors1[0]);
- v3i(v1[0]);
- cpack(colors1[3]);
- v3i(v1[3]);
- cpack(colors2[1]);
- v3i(v2[1]);
- cpack(colors2[0]);
- v3i(v2[0]);
- endpolygon();
-
- bgnpolygon();
- cpack(colors1[2]);
- v3i(v1[2]);
- cpack(colors1[3]);
- v3i(v1[3]);
- cpack(colors2[1]);
- v3i(v2[1]);
- cpack(colors2[2]);
- v3i(v2[2]);
- endpolygon();
- bgnpolygon();
- cpack(colors1[1]);
- v3i(v1[1]);
- cpack(colors1[0]);
- v3i(v1[0]);
- cpack(colors2[0]);
- v3i(v2[0]);
- cpack(colors2[3]);
- v3i(v2[3]);
- endpolygon();
- }
-
- /** eof *********************************************************************/
-